package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    void update(Orders orders);

//    Page<Orders> pageByCondition(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select *from orders ")
    List<Orders> list();

    @Select("select *from orders where id=#{id}")
    Orders getById(Long id);



    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 分页条件查询并按下单时间排序
     * @param ordersPageQueryDTO
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where status=#{status} and order_time<#{localDateTime}")
    List<Orders>  getOrderByStatusAndOrderTimeLT(Integer status, LocalDateTime localDateTime);

    /**
     * 统计每日的的销售额
     * @param map
     * @return
     */
    Double sumBymap(HashMap<String, Object> map);

    /**
     * 获得订单数
     * @param map
     * @return
     */
    Integer countBymap(HashMap<String, Object> map);

    /**
     * 获得top10套餐或菜品
     * @param min
     * @param max
     * @return
     */
    List<GoodsSalesDTO> getSaleTop10(LocalDateTime min, LocalDateTime max);
}
